var amqp = require('amqplib/callback_api');

amqp.connect('amqp://localhost', function (err, conn) {
    conn.createChannel(function (err, ch) {
        var q = 'task_queue';
        var msg = process.argv.slice(2).join(' ') || "Hello World!";

        ch.assertQueue(q, { durable: false });
        // ch.sendToQueue(q, new Buffer(msg));
        ch.sendToQueue(q, new Buffer(msg), {persistent:true});
        console.log("[x] Send '%s'", msg);
    });

    setTimeout(() => {
        conn.close();
        process.exit(0);
    }, 500);
});

